<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="panel panel-default operation" hidden>
  <div class="panel-heading title"></div>
<div class="layui-card-body">
<form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
      <input name="id" hidden/>
        <!-- <div class="layui-form-item">
      <label class="layui-form-label">pid</label>
      <div class="layui-input-block">
        <input type="pid" name="pid" placeholder="请输入pid" autocomplete="off" class="layui-input">
      </div>
    </div> -->
	<div class="layui-form-item">
      <label class="layui-form-label">加油站名称</label>
      <div class="layui-input-block">
        <input type="name" name="name" placeholder="请输入加油站名称" autocomplete="off" class="layui-input">
      </div>
    </div>
        <!-- <div class="layui-form-item">
      <label class="layui-form-label">open</label>
      <div class="layui-input-block">
        <input type="open" name="open" placeholder="请输入open" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">is_parent</label>
      <div class="layui-input-block">
        <input type="isParent" name="isParent" placeholder="请输入is_parent" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">checked</label>
      <div class="layui-input-block">
        <input type="checked" name="checked" placeholder="请输入checked" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">icon</label>
      <div class="layui-input-block">
        <input type="icon" name="icon" placeholder="请输入icon" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">type</label>
      <div class="layui-input-block">
        <input type="type" name="type" placeholder="请输入type" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">gbcode</label>
      <div class="layui-input-block">
        <input type="gbcode" name="gbcode" placeholder="请输入gbcode" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">domain</label>
      <div class="layui-input-block">
        <input type="domain" name="domain" placeholder="请输入domain" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">icon_skin</label>
      <div class="layui-input-block">
        <input type="iconSkin" name="iconSkin" placeholder="请输入icon_skin" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">plugin_name</label>
      <div class="layui-input-block">
        <input type="pluginName" name="pluginName" placeholder="请输入plugin_name" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">indx</label>
      <div class="layui-input-block">
        <input type="indx" name="indx" placeholder="请输入indx" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">platformid</label>
      <div class="layui-input-block">
        <input type="platformid" name="platformid" placeholder="请输入platformid" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">total</label>
      <div class="layui-input-block">
        <input type="total" name="total" placeholder="请输入total" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">onlinetotal</label>
      <div class="layui-input-block">
        <input type="onlinetotal" name="onlinetotal" placeholder="请输入onlinetotal" autocomplete="off" class="layui-input">
      </div>
    </div>
        <div class="layui-form-item">
      <label class="layui-form-label">online</label>
      <div class="layui-input-block">
        <input type="online" name="online" placeholder="请输入online" autocomplete="off" class="layui-input">
      </div>
    </div> -->
        <!-- <div class="layui-form-item">
      <label class="layui-form-label">所在区域</label>
      <div class="layui-input-block">
        <input type="address" name="address" placeholder="请输入所在区域" autocomplete="off" class="layui-input">
      </div>
    </div> -->
     <!-- <div class="layui-form-item">
      <label class="layui-form-label">在线状态</label>
      <div class="layui-input-block">
        <input type="field2" name="field2" placeholder="请输入在线状态" autocomplete="off" class="layui-input">
      </div>
    </div> -->
    <!-- <div class="layui-form-item">
      <label class="layui-form-label">油站类型</label>
      <div class="layui-input-block">
        <input type="field3" name="field3" placeholder="请输入油站类型" autocomplete="off" class="layui-input">
      </div>
    </div> -->
    
    <div class="layui-form-item">
      <label class="layui-form-label">纳税人名称</label>
      <div class="layui-input-block">
        <input type="taxpayerName" name="taxpayerName" placeholder="请输入纳税人名称" autocomplete="off" class="layui-input">
      </div>
     
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label">纳税人识别号</label>
      <div class="layui-input-block">
        <input type="taxpayerCode" name="taxpayerCode" placeholder="请输入纳税人识别号" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    
	<div class="layui-form-item">
      <label class="layui-form-label">所属机关</label>
      <div class="layui-input-block layui-form">
		<select id="taxorgcode">
		</select>
      </div>
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label">加油区总数</label>
      <div class="layui-input-block">
        <input type="gasLocation" name="gasLocation" placeholder="请输入加油区总数" autocomplete="off" class="layui-input">
      </div>
     
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label">可见加油区个数</label>
      <div class="layui-input-block">
        <input type="gasCoverage" name="gasCoverage" placeholder="请输入可见加油区个数" autocomplete="off" class="layui-input">
      </div>
      
    </div>
    
     <div class="layui-form-item">
      <label class="layui-form-label">汽油价格</label>
      <div class="layui-input-block">
        <input type="gasoline" name="gasoline" placeholder="请输入汽油价格" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label">汽油(摩托)价格</label>
      <div class="layui-input-block">
        <input type="gasolineMoto" name="gasolineMoto" placeholder="请输入汽油(摩托)价格" autocomplete="off" class="layui-input">
      </div>
    </div>    
    
     <div class="layui-form-item">
      <label class="layui-form-label">汽油(农用车)价格</label>
      <div class="layui-input-block">
        <input type="gasolineFarming" name="gasolineFarming" placeholder="请输入汽油(农用车)价格" autocomplete="off" class="layui-input">
      </div>
    </div>
    
     <div class="layui-form-item">
      <label class="layui-form-label">汽油(轻卡)价格</label>
      <div class="layui-input-block">
        <input type="gasolineLighttruck" name="gasolineLighttruck" placeholder="请输入汽油(轻卡)价格" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label">柴油价格</label>
      <div class="layui-input-block">
        <input type="diesel" name="diesel" placeholder="请输入柴油价格" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label">油站类型</label>
	  <div class="layui-input-block layui-form">
		<select id="gastype">
			<option value = ''>请选择油站类型</option>
			<option value = "普通站">普通站</option>
			<option value = "汽油站">汽油站</option>
			<option value = "柴油站">柴油站</option>
		</select>
      </div>
    </div>   
    
  <div class="layui-form-item">
  <div class="layui-input-block">
    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
    <button  class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
  </div>
</div>
</form>
</div>
</div>

<div class="table_div">
  <div id="searchParam"  >
    <div class="layui-form-item">
      
      <div class="layui-input-inline layui-form">
      	<select id="taxorgcodeInput">
		</select>
      </div>
      
      <div class="layui-input-inline">
        <input type="text" id="nameInput" class="layui-input"  autocomplete="off" placeholder="请输入加油站名称">
      </div>

	  <div class="layui-input-inline">
        <input type="text" id="taxpayerCodeInput" class="layui-input"  autocomplete="off" placeholder="请输入纳税人识别号">
      </div>

      <div class="layui-input-inline ">
        <button class="layui-btn" onclick="search()"  id="search">查询</button>
        <button class="layui-btn" id="export">导出</button>
      </div>
    </div>

  </div>
  <table class="layui-table" id="showTable" lay-filter="showTable" ></table>
</div>
<script type="text/html" id="toolbar">
  
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="analysisConfirm">确认分析</button>
    <button class="layui-btn layui-btn-sm" lay-event="analysisCancel">取消分析</button>
  </div>
  
</script>
<script type="text/html" id="tool"> 
  <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>
</script>

</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
  //获取token
  var token = CoreUtil.getData("access_token");
  //地址栏转义token中的#号
  var tokenQuery = token.replace("#", "%23");
  var tableIns1;
  var table = layui.table;
  var form = layui.form;
  var layer = layui.layer;
  var $ = jQuery = layui.jquery;
  var laydate = layui.laydate;
  
  $(function() {
	  // 加载机关
      CoreUtil.sendGet("/sys/deptlist",null , function(res) {
			if (res.code == '0') {
				var value = res.data[0];
				var opt = "<option value = ''>请选择所属机关</option>";
				for (var i in value) {
					opt += '<option value = "' + value[i].id + '">'
							+ value[i].name + '</option>';
				}
				
				$("#taxorgcodeInput").html(opt);
				form.render('select'); //需要渲染一下
			} else {
				layer.msg(res.msg);
				return false;
			}
		}, false, false);
		
  });
  

  $(function() {
	  // 加载机关
      CoreUtil.sendGet("/sys/deptlist",null , function(res) {
			if (res.code == '0') {
				var value = res.data[0];
				var opt = "<option value = ''>请选择所属机关</option>";
				for (var i in value) {
					opt += '<option value = "' + value[i].id + '">'
							+ value[i].name + '</option>';
				}
				
				$("#taxorgcode").html(opt);
				form.render('select'); //需要渲染一下
			} else {
				layer.msg(res.msg);
				return false;
			}
		}, false, false);
		
  });
  
  
  layui.use(['table', 'layer', 'laydate'], function () {

    //加载table
    tableIns1 = table.render({
      elem: '#showTable'
      , contentType: 'application/json'
      , headers: {"authorization": token}
      , page: true //开启分页
      , url: '/gas/stationinfo/list1' //数据接口
      , method: 'POST'
      , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
        return {
          "code": res.code, //解析接口状态
          "msg": res.msg, //解析提示文本
          "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
          "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
        }
      }
      , cols: [
        [
          {type: 'checkbox', fixed: 'left'},
          {field: 'id', title: '主键', sort: true, hide: true},
          /* {field: 'pid', title: 'pid', sort: true}, */
          {field: 'name', title: '加油站名称', width: 520,sort: true},
          {field: 'isAnalyse', title: '是否分析', width: 120,sort: true, templet: function(d) {
				if(d.isAnalyse == "Y"){
					return "是";
				}else{
					return "否";
				}
          }},
          
          /* {field: 'address', title: '所在区域', width: 220, hide: true,sort: true}, */
          {field: 'taxpayerName', title: '纳税人名称', width: 220,sort: true},
          
          {field: 'taxpayerCode', title: '纳税人识别号', width: 220,sort: true
        	  , templet:function(d){return d.taxpayerCode + "\t"}
          },
          
          {field: 'taxorgName', title: '所属机关名称', width: 220,sort: true},
          
          {field: 'taxorgcode', title: '所属机关代码' , hide: true, width: 220, sort: true},
          
          {field: 'online', title: '在线状态', width: 120,sort: true, templet: function(d) {
				if(d.online == "0"){
					return "离线";
				}else{
					return "在线";
				}
          }},
          {field: 'gasLocation', title: '加油区总数' ,  width: 110, sort: true},
          {field: 'gasCoverage', title: '可见加油区个数' ,  width: 120, sort: true},
          
          {field: 'gastype', title: '油站类型' ,  width: 110, sort: true},
          {field: 'gasoline', title: '汽油价格' ,  width: 120, sort: true},
          {field: 'gasolineMoto', title: '汽油(摩托)价格' ,  width: 110, sort: true},
          {field: 'gasolineFarming', title: '汽油(农用车)价格' ,  width: 120, sort: true},
          {field: 'gasolineLighttruck', title: '汽油(轻卡)价格' ,  width: 110, sort: true},
          {field: 'diesel', title: '柴油价格' ,  width: 120, sort: true},
          
          {width: 90, toolbar: "#tool", title: '操作', fixed: 'right'}
        ]
      ]
      , toolbar: '#toolbar'
    });


    //表头工具
    table.on('toolbar(showTable)', function(obj){
      switch(obj.event){
        case 'analysisCancel':
          var checkStatus = table.checkStatus(obj.config.id);
          var data = checkStatus.data;
          if(data.length==0){
            layer.msg("请选择要批量确认分析的列");
          }else {
            var ids = [];
            $(data).each(function (index,item) {
              ids.push(item.id);
            });
            tipDialog(ids,"N");
          }
          break;
        case 'analysisConfirm':
        	var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if(data.length==0){
              layer.msg("请选择要批量取消分析的列");
            }else {
              var ids = [];
              $(data).each(function (index,item) {
                ids.push(item.id);
              });
              tipDialog(ids,"Y");
            }
          break;
      };
    });
    //列操作
    table.on('tool(showTable)',function (obj) {
      var data = obj.data;
      switch (obj.event) {
        case 'del':
          var ids=[];
          ids.push(data.id);
          tipDialog(ids);
          break;
        case 'edit':
          $(".table_div").hide();
          $(".operation").show();
          $(".title").html("编辑");
          
          $("#taxorgcode").val(data.taxorgcode);
          form.render('select'); 

          $(".operation input[name=id]").val(data.id);
          $(".operation input[name=pid]").val(data.pid);
          
          $(".operation input[name=name]").val(data.name);
          // $(".operation input[name=name]").attr("readonly",true);
          // $(".operation input[name=name]").attr("disabled", true);
          
          $(".operation input[name=open]").val(data.open);
          $(".operation input[name=isParent]").val(data.isParent);
          $(".operation input[name=checked]").val(data.checked);
          $(".operation input[name=icon]").val(data.icon);
          $(".operation input[name=type]").val(data.type);
          $(".operation input[name=gbcode]").val(data.gbcode);
          $(".operation input[name=domain]").val(data.domain);
          $(".operation input[name=iconSkin]").val(data.iconSkin);
          $(".operation input[name=pluginName]").val(data.pluginName);
          $(".operation input[name=indx]").val(data.indx);
          $(".operation input[name=platformid]").val(data.platformid);
          $(".operation input[name=total]").val(data.total);
          $(".operation input[name=onlinetotal]").val(data.onlinetotal);
          $(".operation input[name=online]").val(data.online);
          
          $(".operation input[name=address]").val(data.address);
          $(".operation input[name=taxpayerName]").val(data.taxpayerName);
          $(".operation input[name=taxpayerCode]").val(data.taxpayerCode);
               
          
          $("#gastype").val(data.gastype);
          form.render('select');
          $(".operation input[name=gasoline]").val(data.gasoline);
          $(".operation input[name=gasolineMoto]").val(data.gasolineMoto);
          $(".operation input[name=gasolineFarming]").val(data.gasolineFarming);
          $(".operation input[name=gasolineLighttruck]").val(data.gasolineLighttruck);
          $(".operation input[name=diesel]").val(data.diesel);
          
          
          $(".operation input[name=field2]").val(data.field2);
          
          $(".operation input[name=field3]").val(data.field3);
          $(".operation input[name=field4]").val(data.field4);
          $(".operation input[name=field5]").val(data.field5);
          $(".operation input[name=deleted]").val(data.deleted);
          $(".operation input[name=createId]").val(data.createId);
          $(".operation input[name=updateId]").val(data.updateId);
          $(".operation input[name=createWhere]").val(data.createWhere);
          $(".operation input[name=createTime]").val(data.createTime);
          $(".operation input[name=updateTime]").val(data.updateTime);
          
          $(".operation input[name=gasLocation]").val(data.gasLocation);
          $(".operation input[name=gasCoverage]").val(data.gasCoverage);
          
          break;
      }
    });

    //导出
    $('#export').on('click', function () {
      //原先分页limit
      var exportParams = {
	        limit: -1,
	        name: $("#nameInput").val(),
	        taxorgcode : $("#taxorgcodeInput").val(),
	    	taxpayerCode : $("#taxpayerCodeInput").val(),

      };
      
      CoreUtil.sendPost("/gas/stationinfo/list1", exportParams, function (res) {
        //初始化渲染数据
        if (res.data != null && res.data.records != null) {
          table.exportFile(tableIns1.config.id, res.data.records, 'xls');
        }
      });
      
    });

    // 是否分析
    var tipDialog=function (ids,key) {
    	var _content = "";
    	var _url = "?";
    	if(key == "Y"){
    		_content = "确认分析吗?";
    		_url = "/gas/stationinfo/analysisConfirm";
      	}else if(key == "N"){
      		_content = "取消分析吗?";
    		_url = "/gas/stationinfo/analysisCancel";
      	}else{
      		layer.msg("key值正确，请刷新页面后再试试！");
      		return false;
      	}
    	
    	layer.open({
        content: _content,
        yes: function(index, layero){
          layer.close(index); //如果设定了yes回调，需进行手工关闭
          CoreUtil.sendPost(_url,ids,function (res) {
            layer.msg(res.msg, {time:1000},function () {
              search();
            });
          });
        }
      });
    };

    //返回
    $("#btn_cancel").click(function() {
      $(".table_div").show();
      $(".operation").hide();
      return false;
    });

    //监听保存
    form.on('submit(submit)', function(data){
    	var taxorgcode = $("#taxorgcode").val();
    	var gastype = $("#gastype").val();

    	data.field.taxorgcode = taxorgcode;
    	data.field.gastype = gastype;

    	if(data.field.id===undefined || data.field.id===null || data.field.id===""){
        	CoreUtil.sendPost("/gas/stationinfo/add",data.field,function (res) {
          		if(res.code == 0){
          			$(".table_div").show();
              		$(".operation").hide();
              		search();
          		}else{
          			layer.msg(res.msg);
          			return false;
          		}
        		
        	});
      	}else {
        	CoreUtil.sendPut("/gas/stationinfo/update",data.field,function (res) {
        		if(res.code == 0){
          			$(".table_div").show();
              		$(".operation").hide();
              		search();
          		}else{
          			layer.msg(res.msg);
          			return false;
          		}
        	});
        }

      return false;
    });
  });

  //执行查询
  function search() {
    //这里以搜索为例
    tableIns1.reload({
      where: { //设定异步数据接口的额外参数，任意设
    	  name: $("#nameInput").val(),
    	  taxorgcode : $("#taxorgcodeInput").val(),
    	  taxpayerCode : $("#taxpayerCodeInput").val(),
      }
      , page: {
        curr: 1 //重新从第 1 页开始
      }
    });
  };
</script>